class HobbiesController < ApplicationController
  #MODULE: Configuraciones
  
  # GET /hobbies
  # GET /hobbies.xml
  def index #DESC: Listar los hobbies
    @hobbies = Hobbie.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @hobbies }
    end
  end

  # GET /hobbies/1
  # GET /hobbies/1.xml
  def show #DESC: Ver detalles de un hobbie
    @hobbie = Hobbie.find(params[:id])
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @hobbie }
    end
  end

  # GET /hobbies/new
  # GET /hobbies/new.xml
  def new #DESC: Agregar un nuevo hobbie
    @hobbie = Hobbie.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @hobbie }
    end
  end

  # GET /hobbies/1/edit
  def edit  #DESC: Editar hobbies
    @hobbie = Hobbie.find(params[:id])
  end

  # POST /hobbies
  # POST /hobbies.xml
  def create
    @hobbie = Hobbie.new(params[:hobbie])
    respond_to do |format|
      if @hobbie.save
        flash[:notice] =  'Hobbie creada correctamente.'
        format.html { params[:oper].nil? ? redirect_to(@hobbie) : render(:text => "Ok")}
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @hobbie.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /hobbies/1
  # PUT /hobbies/1.xml
  def update
    @hobbie = Hobbie.find(params[:id])

    respond_to do |format|
      if @hobbie.update_attributes(params[:hobbie])
        flash[:notice] = 'Hobbie actualizado correctamente.'
        format.html { redirect_to(@hobbie) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @hobbie.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /hobbies/1
  # DELETE /hobbies/1.xml
  def destroy #DESC: Eliminar hobbies
    @hobbie = Hobbie.find(params[:id])
    @hobbie.destroy

    respond_to do |format|
      format.html { redirect_to(hobbies_url) }
      format.xml  { head :ok }
    end
  end
   
end
